<%@page import="org.shop.entity.security.MyUserDetail" %>
<%@page import="org.shop.util.ObjUtil" %>
<%@page import="org.springframework.security.core.context.SecurityContextImpl" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";

    SecurityContextImpl securityContextImpl = (SecurityContextImpl) request.getSession().getAttribute("SPRING_SECURITY_CONTEXT");
    MyUserDetail ud = null;
    Byte state = 1;
    if (ObjUtil.isNotNullAndEmpty(securityContextImpl)) {
        ud = (MyUserDetail) securityContextImpl.getAuthentication().getPrincipal();
        state = ud.getState();
    }
%>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1 user-scalable=0">
    <title>问答</title>
    <link rel="stylesheet" href="<%=basePath%>assets/css/public.css">
    <link rel="stylesheet" href="<%=basePath%>assets/css/page.css">
    <link rel="stylesheet" href="<%=basePath%>assets/font-awesome-4.7.0/css/font-awesome.min.css">
    <script src="<%=basePath%>assets/js/jquery-1.8.3.min.js"></script>
    <script src="<%=basePath%>assets/js/fontSize.js"></script>
    <link href="<%=basePath%>/assets/layer/mobile/need/layer.css" rel="stylesheet" type="text/css">
	<script src="<%=basePath%>/assets/layer/mobile/layer.js"></script>
    <style>
        body {
            padding-top: 0.8rem;
            padding-bottom: 1.6rem;
        }
        .header_ul li {
            float: left;
            width: 25%;
        }

        .header_ul li a {
            font-size: 0.28rem;
            height: 0.75rem;
            line-height: 0.8rem;
            padding: 0 0.2rem;
            display: inline-block;
        }

        .header_ul li a.active {
            color: #FF3D20;
            border-bottom: 2px solid #FF3D20;
        }

        .activity_list{
            padding:0 0.2rem;
        }
        .activity_info{
            height:2rem;
            border-bottom: 2px solid #E9E9E9;
            border-right: 2px solid #E9E9E9;
            margin: 0.2rem 0;
            box-shadow: 0 0 0.2rem #E5E5E5;
            border-radius: 0.1rem;
            overflow: hidden;
        }
        .activity_img{
            width:45%;
        }
        .activity_img img{
            width:100%;
            height:2rem;
        }
        .activity_details{
            width:51%;
            height:1.8rem;
            padding:2%;
            position: relative;
        }
        .activity_name{
            font-size: 0.26rem;
            line-height: 0.36rem;
        }
        .info{
            position: absolute;
            bottom:0;
            height:0.8rem;
            line-height: 0.4rem;
        }
        .name {
            font-size: 0.24rem;
            color: #747474;
        }

        .time {
            color: #BABABA;
            font-size: 0.2rem;
        }
        .clock{
            background-image: url("<%=basePath%>assets/images/clock.png");
            width:0.24rem;
            height:0.24rem;
            display: inline-block;
            background-size: cover;
            margin-right: 2px;
            margin-top: 2px;
        }
        .find a .img{
            display: none;
        }
        .find a .img2{
            display: block;
        }
        .find a p{
            color: #FF3F25;
        }
    </style>
</head>
<body>
<input id="basePath" type="hidden" value="<%=basePath%>">
<div class="header">
    <ul class="header_ul">
        <li class="forum"><a>论坛</a></li>
        <li class="question_answer"><a>问答</a></li>
        <li class="activity"><a class="active">活动</a></li>
        <li class="invite"><a>招聘</a></li>
    </ul>
</div>
<div class="activity_list"></div>
<%@ include file="../footer.jsp" %>
</body>
<script>
	//滚动加载
	var geting = false;//是否加载信息，默认为false
	var currentPage = 1;//当前页
	var pageSize = 10;//每页数据数
	
	//加载
	$(function(){
		getData();
		//加载方法
		$(window).scroll(function () {
			if (geting) {
	        	return;
	        }
	        var scrollTop = $(this).scrollTop();
	        var scrollHeight = $(document).height();
	        var windowHeight = $(this).height();
	        if (scrollTop + windowHeight == scrollHeight) {
	        	currentPage++;
	            getData();
	        }
	    });

		
	});
	
	//获取页面数据
	function getData() {
    	geting = true;
    	$.ajax({
			url : "<%=basePath%>app/getActivityList",
			async:false,
			dataType : "json",
			type : "post",
			data : {
				"currentPage" : currentPage,
				"pageSize" : pageSize
			},
			success : function(data) {
				$.each(data, function (i, item) {
					var imgStr = '';
					//判断照片
					if(item.photo.length>0){
						var photoArr = new Array();
						photoArr = item.photo.split(',');
						//随机图片
						if(photoArr.length==1){
							imgStr = '<img src="<%=basePath%>app/getGoodsPhotoByName?goodsImage='+photoArr+'" alt="">';
						}else{
							var id = parseInt(Math.random()*(photoArr.length),10);
							imgStr = '<img src="<%=basePath%>app/getGoodsPhotoByName?goodsImage='+photoArr[id]+'" alt="">';
						}
					}else{
						imgStr = '<img src="<%=basePath%>assets/images/timg(2).jpg" alt="">';
					}
					var html = '<div class="activity_info" onclick="toActivityDetails('+item.activityId+')">'+
				            '<div class="activity_img float_l">'+
				                ''+imgStr+''+
				            '</div>'+
				            '<div class="activity_details float_l">'+
				                '<div class="activity_name">'+item.title+'</div>'+
				                '<div class="info">'+
					                '<span class="name">'+item.userName+'</span><br>'+
					                '<span class="time">'+item.createDate+'</span>'+
				            '</div>'+
				        '</div>';
					$(".activity_list").append(html);
					geting = false;
				});
			},
			error : function(data) {
				layer.open({
				    content: '网络错误~'
				    ,skin: 'msg'
				    ,time: 3 //3秒后自动关闭
				  });
			}
		})
	};

	//活动详情跳转事件
    function toActivityDetails(activityId){
    	window.location.href="<%=basePath%>jsp/app/find/activity_details.jsp?activityId="+activityId;
    }
	
    //顶层切换
    $(".header_ul a").click(function () {
        $(".header_ul a").removeClass("active");
        $(this).addClass("active");
    });
    $(".forum").click(function(){
        window.location.href="<%=basePath%>jsp/app/find/forum.jsp";
    });
    $(".answer_info").click(function(){
        window.location.href="<%=basePath%>jsp/app/find/questionsAnswersDetails.jsp";
    });
    $(".question_answer").click(function(){
        window.location.href="<%=basePath%>jsp/app/find/questionsAnswers.jsp";
    });
    $(".invite").click(function(){
        window.location.href="<%=basePath%>jsp/app/find/invite.jsp";
    });
	
</script>
</html>
